package com.example.ByteStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * @author Jason
 * @PACKAGE_NAME com.example.ByteStream
 * @Description OutputStreamWriter写入文件
 * @date 2023-12-13 14:33
 */
public class OutputStreamWriterDemo {
    public static void main(String[] args) throws IOException {
        //1.创建流
        FileOutputStream fos = new FileOutputStream("d:\\aaa.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, "GB2312");
//        OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
        //2.写入
        for (int i = 0; i < 10; i++) {
            osw.write("你好" + i + "\n\r");
            osw.flush();
        }
        //3.关闭
        osw.close();
    }
}
